﻿using Castle.DynamicProxy;

namespace EventHandlerDemo.Infrastructure.Interceptors
{
    /// <summary>
    /// https://www.cnblogs.com/wswind/p/autofac-asyncinterceptor.html
    /// https://stackoverflow.com/questions/28099669/intercept-async-method-that-returns-generic-task-via-dynamicproxy/39784559#39784559
    /// </summary>
    public class UowTransactionInterceptor : IInterceptor
    {
        private readonly UowTransactionAsyncInterceptor _uowAsyncInterceptor;

        public UowTransactionInterceptor(UowTransactionAsyncInterceptor uowAsyncInterceptor)
        {
            _uowAsyncInterceptor = uowAsyncInterceptor;
        }

        public void Intercept(IInvocation invocation)
        {
            _uowAsyncInterceptor.ToInterceptor().Intercept(invocation);
        }
    }
}
